﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace SultanModLoader
{
    public class ModInfo
    {
        public string Name { get; set; }
        public string Version { get; set; }
        public string Author { get; set; }
        public string Description { get; set; }
        [JsonIgnore]
        public bool Enable { get; set; } = true;
        [JsonIgnore]
        public string ConfigPath { get; set; }
        [JsonIgnore]
        public string ModDirectory { get; set; }
        private string _ModKey;
        public string ModKey { get
            {
                if (_ModKey == null) _ModKey = $"|>Name:{Name}$Author:{Author}<|";
                return _ModKey;
            } }
        // Json文件列表
        [JsonIgnore]
        public List<string> JsonFilePathList { get; set; } = new List<string>();
        /// <summary>
        /// 根据ModJsonOption分类存放的Jtoken<br/>
        /// 第一级Key：ModJsonOption<br/>
        /// 第二级Key: 文件相对路径<br/>
        /// Value: List [ ( JToken, JToken来源文件相对路径 ) ... ]
        /// </summary>
        public Dictionary<string, Dictionary<string, List<(JToken, string)>>> JTokenDictsByOption { get; } = ModJsonOption.Options.ToDictionary(
                keySelector: option => option, 
                elementSelector: option => new Dictionary<string,List<(JToken, string)>>()
            );


        public Dictionary<string, bool> ModuleToggle { get; set; } = new Dictionary<string, bool>();

        public override string ToString()
        {
            return string.Format(
                "Mod Information:\n" +
                "  Name:        {0}\n" +
                "  Version:     {1}\n" +
                "  Author:      {2}\n" +
                "  Description: {3}\n" +
                "  Status:      {4}\n" +
                "  Directory:   {5}\n" +
                "  Config:      {6}",
                Name, Version, Author, Description,
                Enable ? "Enable" : "Disabled",
                ModDirectory, ConfigPath);
        }

    }

}
